﻿Imports System.IO
Imports System.Text
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Runtime.Serialization
Module modUtilidades

    Public Sub guardarConfiguracion(ByVal objConfiguracion As Object)
        'deserializar
        If (objConfiguracion Is Nothing) Then
            Exit Sub
        End If
        Dim stream As FileStream = Nothing
        Try
            Dim bformatter As BinaryFormatter = New BinaryFormatter()
            Dim objStream As FileStream = New FileStream("sistogeo.scfn", FileMode.Create)
            bformatter.Serialize(objStream, objConfiguracion)
            objStream.Close()
            objStream.Dispose()
        Catch ex As Exception
            MsgBox("Error: " & ex.Message)
        End Try
    End Sub

    Public Function cargarConfiguracion(ByVal objConfiguracion As Object) As Object
        'deserializar
        If (objConfiguracion Is Nothing) Then
            objConfiguracion = New Configuracion()
        End If
        Dim stream As FileStream = Nothing
        Try
            Dim bformatter As BinaryFormatter = New BinaryFormatter()
            stream = New FileStream("sistogeo.scfn", FileMode.Open)
            Dim d(stream.Length) As Byte
            objConfiguracion = DirectCast(bformatter.Deserialize(stream), Configuracion)
            stream.Close()
            stream.Dispose()
        Catch ex As Exception
            Try
                stream.Close()
            Catch ex2 As Exception
            End Try
            'Throw ex
        End Try
        Return objConfiguracion
    End Function


End Module
